/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package desint;

import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import javax.swing.JComponent;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

/**
 *
 * @author Leonardo Lino
 */
public class ColorTableCellRenderer extends JComponent implements TableCellRenderer {
    // The current color to display
    Color curColor;

    public Component getTableCellRendererComponent(JTable table, Object value,
            boolean isSelected, boolean hasFocus, int rowIndex, int vColIndex) {
        // Set the color to paint
        if (curColor instanceof Color) {
            curColor = (Color)value;
        } else {
            // If color unknown, use table's background
            curColor = table.getBackground();
        }
        return this;
    }

    // Paint current color
    public void paint(Graphics g) {
        g.setColor(curColor);
        g.fillRect(0, 0, getWidth()-1, getHeight()-1);
    }
}
